<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Cache;
use App\Exceptions\ApiException;

class AdminToken
{
    /**
     * @param $request
     * @param Closure $next
     * @return mixed
     * @throws ApiException
     */
    public function handle($request, Closure $next)
    {
        $token = $request->input('ticket');

        if (!$token) {
            throw new ApiException('请先登录', 0);
        }

        $user = Cache::get($token);
        if (!$user) {
            throw new ApiException('请先登录', 0);
        }
        return $next($request);
    }
}
